<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>场次</title>
    <style>
        table,
        td,th{
            border: 1px solid black;
        }
    </style>
</head>

<body>
    
    <hr>
    <table id="subtable">
        <thead>
            <tr>
                <th>场次编号</th>
                <th>电影开场时间</th>
                <th>电影结束时间</th>
                <th>影厅类型</th>
                <th>价格</th>
                <th>购票</th>
            </tr>
        </thead>
        <tbody id="tablebody"></tbody>
    </table>
</body>

<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>

<script>
    var cinemaId = sessionStorage.getItem("cinemaId");
    var movieId = sessionStorage.getItem("movieId");
    var date = sessionStorage.getItem("date");
    console.log("电影院Id:"+cinemaId+"电影Id:"+movieId+"日期:"+date);
    url = "http://localhost:8090/wanda/screens";
    pdata = {"cinemaId":cinemaId,"movieId":movieId,"date":date}
    $.get(url,pdata,function(jsondata){
        console.log(jsondata);
        if(jsondata.code == "200"){
            $.each(jsondata.data,function(index,item){
                var str = `
                    <tr>
                        <td>${index+1}</td>
                        <td>${item.startTime}</td>
                        <td>${item.endTime}</td>
                        <td>${item.hallId}号厅</td>
                        <td>${item.price}</td>
                        <td>
                            <button name="${item.id}">选座</button>
                        </td>
                    </tr>
                `;
                $('#tablebody').append(str);
            })
        }else{
            alert("对不起，不可以选座");
        }

        $.each($('button[name]'),function(index,item){
            $(item).on('click',function(event){
                const button = event.currentTarget;
                const screenId = $(button).attr('name');
                console.log(screenId);
                sessionStorage.setItem("screenId",screenId);
                window.location.href = "site.html";
            })
        })
    },"json")
</script>

</html>